import pymysql
from pyecharts.charts import Bar
from pyecharts import options

# 连接数据库.
db = pymysql.connect(
    host="localhost",
    user="root",
    password="123456",
    database="crawlerdemo",
    charset='utf8'
)
cursor = db.cursor()
# 这里是获取各城市的最低薪水.
sql="select min(job_sal),job_place from job group by job_place order by min(job_sal) limit 5"

# 定义列表
sal = []
city = []

try:
    cursor.execute(sql)
    res = cursor.fetchall()
    for i in res:
        sal.append(i[0])
        city.append(i[1])
except:
    print("查询有误")
# 创建柱状图对象.
bar=Bar()
# 增加x的数据.
bar.add_xaxis(city)
# 添加y轴的数据"月薪水/元" 是y轴数据的单位.
bar.add_yaxis("月薪水/元",sal)
# 添加表格的正标题和单位.
bar.set_global_opts(title_opts=options.TitleOpts(title="各城市中工资最低的五个城市",subtitle="单位/元"))
bar.render("barmin.html")